package com.yugong.controller;

import com.github.pagehelper.PageInfo;
import com.yugong.common.Result;
import com.yugong.entity.vo.request.MajorRequestVO;
import com.yugong.entity.vo.response.MajorListResponseVO;
import com.yugong.service.MajorService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 专业控制器类
 *
 * @author yugong
 * @date 2024/2/21
 */
@RestController
@RequestMapping("/api/major")
public class MajorController {
    @Resource
    private MajorService majorService;

    /**
     * 根据订单班管理员工号查询订单班管理员对应的专业
     *
     * @param orderClassAdminNo 订单班管理员工号
     * @return 订单班管理员对应的专业
     */
    @GetMapping("/find-major-order-class-admin-no")
    public Result findMajorByOrderClassAdminNo(@RequestParam String orderClassAdminNo) {
        List<MajorListResponseVO> majorListVOListResponse = majorService.findMajorByOrderClassAdminNo(orderClassAdminNo);
        return Result.success(majorListVOListResponse);
    }

    /**
     * 根据专业名查询专业
     *
     * @param pageNum   当前页
     * @param pageSize  当前页数据总数
     * @param majorName 专业名
     * @return 专业
     */
    @GetMapping("/find-major-page")
    public Result findMajorPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                @RequestParam(defaultValue = "5") Integer pageSize,
                                @RequestParam String majorName) {
        PageInfo<MajorListResponseVO> majorListResponseVOPageInfo = majorService.findMajor(pageNum, pageSize, majorName);
        return Result.success(majorListResponseVOPageInfo);
    }

    /**
     * 新增专业
     *
     * @param majorRequestVO 专业请求实体类
     * @return 响应码
     */
    @PostMapping("/add-major")
    public Result addMajor(@RequestBody MajorRequestVO majorRequestVO) {
        int addFlag = majorService.addMajor(majorRequestVO);
        return Result.success(addFlag);
    }

    /**
     * 更新专业
     *
     * @param majorRequestVO 专业请求实体类
     * @return 响应码
     */
    @PutMapping("/update-major")
    public Result updateMajor(@RequestBody MajorRequestVO majorRequestVO) {
        int updateFlag = majorService.updateMajor(majorRequestVO);
        return Result.success(updateFlag);
    }

    /**
     * 删除专业
     *
     * @param majorNo 专业号
     * @return 响应码
     */
    @DeleteMapping("/delete-major/{majorNo}")
    public Result deleteMajor(@PathVariable String majorNo) {
        int deleteFlag = majorService.deleteMajor(majorNo);
        return Result.success(deleteFlag);
    }
}
